<template>
  <div class="app-container">
    <!--    <el-row :gutter="20">-->
    <!--      &lt;!&ndash;部门数据&ndash;&gt;-->
    <!--      <el-col :span="4" :xs="24">-->
    <!--        <div class="head-container">-->
    <!--          <el-input-->
    <!--            v-model="queryParams.teamId"-->
    <!--            placeholder="请输入部门名称"-->
    <!--            clearable-->
    <!--            size="small"-->
    <!--            prefix-icon="el-icon-search"-->
    <!--            style="margin-bottom: 20px"-->
    <!--          />-->
    <!--        </div>-->
    <!--        <div class="head-container">-->
    <!--          <el-tree-->
    <!--            :data="deptOptions"-->
    <!--            :props="defaultProps"-->
    <!--            :expand-on-click-node="false"-->
    <!--            :filter-node-method="filterNode"-->
    <!--            ref="tree"-->
    <!--            node-key="value"-->
    <!--            default-expand-all-->
    <!--            highlight-current-->
    <!--            @node-click="handleNodeClick"-->
    <!--          />-->
    <!--        </div>-->
    <!--      </el-col>-->
    <!--      <el-col :span="20" :xs="24">-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="220px">
      <el-row>
        <el-form-item label="账号" prop="account">
          <el-input v-model="queryParams.account" placeholder="请输入账号" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <!--          <el-form-item label="电话号码" prop="phone">-->
        <!--            <el-input-->
        <!--              v-model="queryParams.phone"-->
        <!--              placeholder="请输入电话号码"-->
        <!--              clearable-->
        <!--              @keyup.enter.native="handleQuery"-->
        <!--            />-->
        <!--          </el-form-item>-->
        <el-form-item label="真实姓名" prop="realName">
          <el-input v-model="queryParams.realName" placeholder="请输入真实姓名" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>

        <!--          <el-form-item label="网格" prop="gridId">-->
        <!--            <el-cascader :options="gridList" v-model="queryParams.gridId" placeholder="请选择网格" size="medium" filterable-->
        <!--                         style="width: 100%"-->
        <!--            ></el-cascader>-->
        <!--          </el-form-item>-->
        <!--      <el-form-item label="所属志愿者队伍" prop="teamId">-->
        <!--        <el-input-->
        <!--          v-model="queryParams.teamId"-->
        <!--          placeholder="请输入所属志愿者队伍"-->
        <!--          clearable-->
        <!--          @keyup.enter.native="handleQuery"-->
        <!--        />-->
        <!--      </el-form-item>-->
        <!--      <el-form-item label="政治身份" prop="politicalIdentityId">-->
        <!--        <el-input-->
        <!--          v-model="queryParams.politicalIdentityId"-->
        <!--          placeholder="请输入政治身份，0:群众 1:中共党员 2:中共预备党员 3:共青团员 4:无党派民主人士"-->
        <!--          clearable-->
        <!--          @keyup.enter.native="handleQuery"-->
        <!--        />-->
        <!--      </el-form-item>-->

        <el-form-item label="联系地址" prop="contactAddress">
          <el-input v-model="queryParams.contactAddress" placeholder="请输入联系地址" clearable
                    @keyup.enter.native="handleQuery" />
        </el-form-item>
      </el-row>
      <el-form-item label="角色" prop="role">
        <el-select v-model="queryParams.role" placeholder="请选择">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="党建引领" prop="role">
        <el-select v-model="queryParams.groupId" placeholder="请选择">
          <el-option v-for="item in groupList" :key="item.id" :label="item.groupName" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="队伍选择" prop="account" v-if="queryParams.role !== 0">
        <el-select v-model="queryParams.teamId" filterable placeholder="请选择">
          <el-option v-for="item in deptOptions[1].children" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
        <!-- <el-cascader v-model="teamId" :options="deptOptions[1].children" :show-all-levels="false"
          filterable></el-cascader> -->
      </el-form-item>
      <!--          <el-form-item label="积分" prop="point">-->
      <!--            <el-input-->
      <!--              v-model="queryParams.point"-->
      <!--              placeholder="请输入积分"-->
      <!--              clearable-->
      <!--              @keyup.enter.native="handleQuery"-->
      <!--            />-->
      <!--          </el-form-item>-->
      <!--      <el-form-item label="工时" prop="workHours">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.workHours"-->
      <!--          placeholder="请输入工时"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="微信的openid，绑定微信时写入" prop="openId">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.openId"-->
      <!--          placeholder="请输入微信的openid，绑定微信时写入"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--          <el-form-item label="身份证号码" prop="idNumber">-->
      <!--            <el-input-->
      <!--              v-model="queryParams.idNumber"-->
      <!--              placeholder="请输入身份证号码"-->
      <!--              clearable-->
      <!--              @keyup.enter.native="handleQuery"-->
      <!--            />-->
      <!--          </el-form-item>-->
      <!--      <el-form-item label="特长，掌握的(生活)技能" prop="forte">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.forte"-->
      <!--          placeholder="请输入特长，掌握的(生活)技能"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['user:management:add']">新增
        </el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="success"-->
      <!--          plain-->
      <!--          icon="el-icon-edit"-->
      <!--          size="mini"-->
      <!--          :disabled="single"-->
      <!--          @click="handleUpdate"-->
      <!--          v-hasPermi="['api:user:edit']"-->
      <!--        >修改</el-button>-->
      <!--      </el-col>-->
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
                   v-hasPermi="['user:management:remove']">删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <!-- <el-button @click="handleExportModal" icon="el-icon-plus" size="mini" plain type="primary">增量导入</el-button> -->
        <fullImportModal title="增量导入" type="import"></fullImportModal>
      </el-col>
      <el-col :span="1.5">
        <fullImportModal title="覆盖导入" type="fullImport"></fullImportModal>
        <!-- <el-button @click="handleExportModal2" icon="el-icon-plus" size="mini" plain type="primary">覆盖导入</el-button> -->
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="warning"-->
      <!--          plain-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="handleExport"-->
      <!--          v-hasPermi="['api:user:export']"-->
      <!--        >导出</el-button>-->
      <!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" fixed />

      <el-table-column width="100" label="真实姓名" align="center" prop="realName" fixed />
      <el-table-column width="120" label="昵称" align="center" prop="nickname">
        <template slot-scope="scope">
          <span>{{ scope.row.nickname.slice(0, 7) }}</span>
        </template>
      </el-table-column>
      <el-table-column width="120" label="电话号码" align="center" prop="phone" />
      <!--      <el-table-column label="所属慈善机构，管理员分配" align="center" prop="organizationId" />-->
      <el-table-column label="角色" align="center" prop="role">
        <template slot-scope="scope">
          <span v-if="scope.row.role === 0">普通用户</span>
          <span v-if="scope.row.role === 1">志愿者</span>
        </template>
      </el-table-column>

      <el-table-column width="180" label="账号注册时间" align="center" prop="registerDatetime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.registerDatetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="密码" align="center" prop="password" />-->
      <el-table-column label="加入志愿者时间" align="center" prop="joinDatetime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.joinDatetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="所属志愿者队伍" align="center" prop="teamId" />-->
      <el-table-column width="180" label="工作单位" align="center" prop="company" />
      <el-table-column label="政治面貌" align="center" prop="politicalIdentityId">
        <template slot-scope="scope">
          <span v-if="scope.row.politicalIdentityId === 0">群众</span>
          <span v-if="scope.row.politicalIdentityId === 1">中共党员</span>
          <span v-if="scope.row.politicalIdentityId === 2">中共预备党员</span>
          <span v-if="scope.row.politicalIdentityId === 3">共青团员</span>
          <span v-if="scope.row.politicalIdentityId === 4">无党派民主人士</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="加入志愿说明" align="center" prop="joinDescription" />-->
      <el-table-column width="180" label="账号" align="center" prop="account" />
      <!--      <el-table-column label="0: 未实名认证，1：已实名认证" align="center" prop="realNameAuthenticated" />-->
      <!--      <el-table-column label="页面分区" align="center" prop="systemArea" />-->
      <el-table-column width="180" label="联系地址" align="center" prop="contactAddress" />
      <!--      <el-table-column label="头像url" align="center" prop="avatar" />-->
      <el-table-column label="积分" align="center" prop="point" />
      <el-table-column label="工时" align="center" prop="workHours" />
      <!--      <el-table-column label="微信的openid，绑定微信时写入" align="center" prop="openId" />-->
      <!--      <el-table-column label="身份证号码" align="center" prop="idNumber" />-->
      <el-table-column width="180" label="生日" align="center" prop="birthDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.sex === 0">男</el-tag>
          <el-tag v-if="scope.row.sex === 1">女</el-tag>
          <el-tag v-if="scope.row.sex === null">未知</el-tag>
        </template>
      </el-table-column>
      <!--      <el-table-column label="特长，掌握的(生活)技能" align="center" prop="forte" />-->
      <el-table-column width="180" label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['user:management:edit']">修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['user:management:remove']">删除
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handlepoint(scope.row)"
                     v-hasPermi="['user:management:point']">积分
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="column.pageNum" :limit.sync="column.pageSize"
                @pagination="getList" />

    <el-dialog :title="title" :visible.sync="vistpoint" width="400px">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="积分" prop="point">
          <el-input v-model="form.point" placeholder="请输入积分" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="PointForm">确 定</el-button>
        <el-button @click="vistpoint = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改用户列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="电话号码" prop="account">
          <el-input v-model="form.account" placeholder="请输入电话号码" />
        </el-form-item>
        <el-form-item label="真实姓名" prop="realName">
          <el-input v-model="form.realName" placeholder="请输入真实姓名" />
        </el-form-item>
        <el-form-item label="昵称" prop="nickname">
          <el-input v-model="form.nickname" placeholder="请输入昵称" />
        </el-form-item>
        <div style="display: flex">
          <el-form-item label="性别" prop="sex">
            <el-select v-model="form.sex" placeholder="请选择">
              <el-option v-for="item in sex" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所属支部">
            <el-select v-model="form.groupId" placeholder="请选择">
              <el-option v-for="item in groupList" :key="item.id" :label="item.groupName" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </div>

        <el-form-item label="角色" prop="role">
          <el-select v-model="form.role" placeholder="请选择">
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="网格" prop="cityId">
          <el-cascader :options="gridList" v-model="form.cityId" placeholder="请选择网格"
                       :props="{ value: 'cityId', label: 'name', children: 'child' }" @keyup.enter.native="handleQuery"
                       size="medium" filterable style="width: 100%"></el-cascader>
        </el-form-item>
        <el-form-item v-if="form.role != 0" label="所属志愿者队伍" prop="teamId">
          <!--          <el-input v-model="form.teamIdList" placeholder="请输入所属志愿者队伍" />-->
          <el-select v-model="form.teamIdList" multiple placeholder="请选择" @change="teamchange">
            <el-option v-for="item in duiwoptions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="form.role == 2" label="管理的队伍：">
          <!--          <el-input v-model="form.teamIdList" placeholder="请输入所属志愿者队伍" />-->
          <el-select v-model="form.managedTeamId" placeholder="请选择">
            <el-option v-for="item in duizoptions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="工作单位" prop="company">
          <el-input v-model="form.company" placeholder="请输入工作单位，用户自己填" />
        </el-form-item>
        <el-form-item label="政治面貌" prop="politicalIdentityId">
          <el-select v-model="form.politicalIdentityId" placeholder="请选择">
            <el-option v-for="item in politicalIdentityId" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
          <!--          <el-input v-model="form.politicalIdentityId" placeholder="请输入政治身份，0:群众 1:中共党员 2:中共预备党员 3:共青团员 4:无党派民主人士" />-->
        </el-form-item>
        <el-form-item label="加入志愿说明" prop="joinDescription">
          <el-input v-model="form.joinDescription" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="联系地址" prop="contactAddress">
          <el-input v-model="form.contactAddress" placeholder="请输入联系地址" />
        </el-form-item>
        <!--        <el-form-item label="头像url" prop="avatar">-->
        <!--          <el-input v-model="form.avatar" placeholder="请输入头像url" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="积分" prop="point">-->
        <!--          <el-input v-model="form.point" placeholder="请输入积分"/>-->
        <!--        </el-form-item>-->
        <el-form-item label="工时" prop="workHours">
          <el-input v-model="form.workHours" placeholder="请输入工时" />
        </el-form-item>
        <el-form-item label="身份证号码" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入身份证号码" />
        </el-form-item>
        <el-form-item label="生日" prop="birthDate">
          <el-date-picker clearable v-model="form.birthDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择生日">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="特长" prop="forte">
          <el-input v-model="form.forte" placeholder="请输入特长，掌握的(生活)技能" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listUser,
  getUser,
  delUser,
  addUser,
  updateUser,
  importUser,
  teamlist,
  updatepoint,
} from '@/api/user/user'
import { listRegion, treeAny } from '@/api/Region/region'
import fullImportModal from './fullImport.vue'
import { allListgroup, listgroup } from '@/api/nameToInfo/nameToInfo'
export default {
  watch: {
    teamName(val) {
      this.$refs.tree.filter(val)
    }
  },
  name: 'User',
  components: { fullImportModal },
  data() {
    return {
      // 队伍名称
      teamName: '',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 积分弹框
      vistpoint: false,
      // 总条数
      total: 0,
      // 用户列表表格数据
      userList: [],
      // 弹出层标题
      title: '',
      teamId: [-1],
      duiwoptions: [],
      // 是否显示弹出层
      open: false,
      politicalIdentityId: [{
        value: 0,
        label: '群众'
      }, {
        value: 1,
        label: '中共党员'
      }, {
        value: 2,
        label: '中共预备党员'
      }, {
        value: 3,
        label: '共青团员'
      }, {
        value: 4,
        label: '无党派民主人士'
      }],
      options: [{
        value: 0,
        label: '普通用户'
      }, {
        value: 1,
        label: '志愿者'
      }, {
        value: 2,
        label: '志愿队长'
      }],
      deptOptions: [
        {
          value: -1,
          label: '普通用户'
        }, {
          value: 1,
          label: '志愿者',
          children: []
        }],
      duizoptions: [],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      sex: [{
        value: 0,
        label: '男'
      }, {
        value: 1,
        label: '女'
      }],
      // 查询参数
      queryParams: {
        // pkId: null,
        // phone: null,
        // nickName: null,
        realName: null,
        role: 1,
        teamId: null,
        account: null,
        contactAddress: null,
        groupId:null
        // company: null,
        // politicalIdentityId: null,
        // joinDescription: null,
        // avatar: null,
        // point: null,
        // workHours: null,
        // idNumber: null,
        // birthDate: null,
        // sex: null,
        // forte: null
      },
      //分页
      column: {
        pageSize: null,
        pageNum: null
      },
      // 表单参数
      form: {
        pkId: null,
        account: null,
        realName: null,
        nickname: null,
        role: null,
        teamIdList: [],
        company: null,
        politicalIdentityId: null,
        joinDescription: null,
        contactAddress: null,
        avatar: null,
        point: null,
        workHours: null,
        idNumber: null,
        birthDate: null,
        sex: null,
        forte: null,
        cityId: [],
        managedTeamId: null
      },
      // 分组列表
      groupList:[],
      // 表单校验
      rules: {
        account: [
          { required: true, message: '请输入手机号', trigger: 'change' }
        ],
        nickname: [
          { required: true, message: '请输入姓名', trigger: 'change' }
        ],
        role: [
          { required: true, message: '请选择角色', trigger: 'change' }
        ],
        teamIdList: [
          { required: true, message: '必须选择志愿队伍', trigger: 'change' }
        ],
        politicalIdentityId: [
          { required: true, message: '必须选择政治身份', trigger: 'change' }
        ],
        workHours: [
          { required: true, message: '请输入工时', trigger: 'change' }
        ],
        point: [
          { required: true, message: '请输入积分', trigger: 'change' }
        ]
        //gridId: [
        //  { required: true, message: '请选择网格', trigger: 'change' }
        //]
      },
      fileList: [],
      flag:true,
      //网格列表
      gridList: []
    }
  },
  created() {
    console.log('11111111111111111111111111')
    // 获取队伍列表
    this.getTeamList()
    this.getgroupList()
    setTimeout(() => {
      console.log(this.$route.query.role,'++++')
      // 判断是否有路由传值进行初始赋值
      if (this.$route.query.role) {
        this.queryParams.role = 1
        this.flag = false
        this.queryParams.groupId = Number(this.$route.query.groupId)
        this.queryParams.teamId = this.findValueByLabel(this.$route.query.teamName)
      }
      /** 查询用户列表列表 */
      this.getList()
      //查询网格列表
      this.getGridList()
    }, 1000);
  },
  methods: {
    //查询网格列表
    getGridList() {
      treeAny().then(response => {
        this.gridList = response
        console.log('网格', this.gridList)
      })
    },
    getgroupList() {
      console.log(this.queryParams)
      allListgroup().then(response => {
        this.groupList = response
      })
    },
    /** 查询用户列表列表 */
    getList() {
      if(this.queryParams.role == 0){
        this.queryParams.teamId=null
      }

      this.loading = true
      console.error(this.queryParams)
      listUser(this.queryParams, this.column).then(response => {
        this.userList = response.pageData
        this.total =Number(response.total)
        this.loading = false
        console.log(this.userList)
      })
    },
    // 获取队伍列表
    getTeamList() {
      teamlist().then(res => {
        this.duiwoptions = res
        this.duiwoptions = this.duiwoptions.map(item => ({
          label: item.name,
          value: item.id
        }))
        this.deptOptions[1].children = this.duiwoptions
      })
    },
    // 根据label获取value
    findValueByLabel(targetLabel) {
      const option = this.deptOptions[1].children.find(opt => opt.label === targetLabel);
      return option ? option.value : null;
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        pkId: null,
        phone: null,
        realName: null,
        nickname: null,
        role: 1,
        teamIdList: [],
        company: null,
        politicalIdentityId: null,
        joinDescription: null,
        contactAddress: null,
        avatar: null,
        point: null,
        workHours: null,
        idNumber: null,
        birthDate: null,
        sex: null,
        forte: null,
        groupId:null,
        cityId: []
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      // if (this.queryParams.role === 0) {
      //   this.teamId = [-1]
      // }
      console.log(this.queryParams)
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryParams.teamId = null
      this.queryParams.groupId = null
      // this.teamId = [-1]
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.pkId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加用户列表'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const pkId = row.uid || this.ids
      getUser(pkId).then(response => {
        console.log(response)
        this.form = {
          groupId:response.groupId,
          uid: response.uid,
          phone: response.phone || response.account,
          account:response.account,
          realName: response.realName,
          nickname: response.nickname,
          role: response.role,
          teamIdList: [],
          company: response.company,
          politicalIdentityId: response.politicalIdentityId,
          joinDescription: response.joinDescription,
          contactAddress: response.contactAddress,
          avatar: response.avatar,
          point: response.point,
          workHours: response.workHours,
          idNumber: response.idNumber,
          birthDate: response.birthDate,
          sex: response.sex,
          forte: response.forte,
          cityId: response.cityIdList,
        }
        console.log(this.form.cityId)
        this.duizoptions = []
        for (let i = 0; i < response.teamIdNamePairList.length; i++) {
          let matchingItems = this.duiwoptions.filter(item => item.value === response.teamIdNamePairList[i])
          this.duizoptions.push(...matchingItems)
        }
        this.form.teamIdList = response.teamIdNamePairList.map(i => (i.id))
        this.open = true
        this.teamchange(this.form.teamIdList)
        this.title = '修改用户列表'
      })

    },
    // 积分修改
    handlepoint(row) {
      this.reset()
      this.title = '修改用户积分'
      const pkId = row.uid || this.ids
      getUser(pkId).then(res => {
        this.form = {
          uid: pkId,
          point: res.point
        }
        this.vistpoint = true
      })
    },
    PointForm() {
      updatepoint(this.form).then(res => {
          this.$modal.msgSuccess('修改成功')
          this.vistpoint = false
      })
    },
    /** 提交按钮 */
    submitForm() {
      console.log(this.form.cityId)
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.form.cityId = this.form.cityId ? this.form.cityId[this.form.cityId.length - 1] : undefined
          if (this.form.uid != null) {
            updateUser(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addUser(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const pkIds = row.uid || this.ids
      this.$modal.confirm('是否确认删除用户列表编号为"' + pkIds + '"的数据项？').then(function () {
        return delUser(pkIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('api/user/export', {
        ...this.queryParams
      }, `user_${new Date().getTime()}.xlsx`)
    },
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    handlePreview(res) {
      console.log(res)
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
    },
    //商品介绍图片
    selectPicListUpload(obj) {
      let fd = new FormData() //参数的格式是formData格式的
      fd.append('multipartFile', obj.file) //参数
      importUser(fd).then(res => {
        console.log(res)
        this.fileList.push({
          name: 'excel', url: this.imgUrl + res.msg
        })
      })
    },
    // teamchange
    teamchange(e) {
      this.duizoptions = []
      for (let i = 0; i < e.length; i++) {
        let matchingItems = this.duiwoptions.filter(item => item.value === e[i])
        this.duizoptions.push(...matchingItems)
      }
    },
    // 树形结构
    handleNodeClick(data) {
      if (data.value === -1) {
        this.queryParams.teamId = null
        this.queryParams.role = 0
        this.getList()
      } else {
        console.log(data.value)
        this.queryParams.teamId = data.value
        this.queryParams.role = 1
        this.getList()
      }
    },
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    }
  }
}
</script>
<style scoped>
.el-dialog {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0px !important;
}
</style>
